package com.yang.contorller;

import com.yang.service.LoginService;
import com.yang.utils.Constants;
import com.yang.utils.JsonResult;
import com.yang.utils.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author 杨天可
 * @Date 2021/6/11 14:28
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/login")
public class LoginController {
    @Resource
    LoginService loginService;

    @GetMapping("/test")
    public Map<String,Object> test(@RequestParam("param") String param){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(Constants.SUCCESS);
        jsonResult.setData(param);
        jsonResult.setMsg("请求成功");
        return  jsonResult.getValues();
    }
    /***
     * 用户登录
     * @return 登录是否成功
     */
    @PostMapping("/userLogin")
    public Map<String,Object> userLogin(@RequestBody  Map<String,Object> map) {
        String phone = (String)map.get("phone");
        String password = (String)map.get("password");
        return loginService.userLogin(phone, password);
    }

    /***
     * 用户退出登录
     * @return 操作结果
     */
    @GetMapping("/logOut")
    public Map<String, Object> logOut() {
        return loginService.loginOut();
    }
}
